﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VirtualPress.Portal.WebLogic;
using VirtualPress.Infrastructure.Entities.Entity;
using VirtualPress.Infrastructure.Entities.Enum;
using VirtualPress.Infrastructure.HitMonitor;
using VirtualPress.Portal.Biz;

namespace VirtualPress.Portal.Web.Controllers
{
    [Compress]
    [ErrorHandle]
    public class ManuscriptsController : SiteBaseController
    {
        //
        // GET: /Manuscripts/

        public ActionResult Index(int id)
        {
            var article = new Article().Find(id.ToString());
            if (article == null || article.Status != ArticleStatus.YiChuBan ||
                article.PeriItem_Id == 0)
            {
                return Redirect("/home/index");
            }
            var journal = new Periodical().Find(article.Peri_Id.ToString());
            if (journal == null)
            {
                return Redirect("/home/index");
            }
            var journalItem = new PeriodicalItem().Find(article.PeriItem_Id.ToString());
            if (journalItem == null)
            {
                return Redirect("/home/index");
            }
            var artileAuthor = new ArticleAuthor().FindAll(c => c.ManuscriptId == article.Id);
            var attachment = new Appendix().Find(c => c.Type == (int)AttachmentType.Manuscript &&
                c.RaletionId == article.Id && c.Status == (int)AttachmentStatus.DingGao);
            ViewBag.Article = article;
            ViewBag.Journal = journal;
            ViewBag.JournalItem = journalItem;
            ViewBag.ArticleAuthor = artileAuthor;
            ViewBag.Attachment = attachment;
            HitMonitor.Instance(HitName.Article, article.Id).Trigger((int)ArticleGetAction.visit);
            ViewBag.RelationJournal = iCache.Get<List<Periodical>>(String.Format("JournalBiz.GetAllRelationJournal_{0}_{1}",
                (int)journal.IndType, 6), () =>
                {
                    return JournalBiz.GetAllRelationJournal(journal.IndType, 6);
                },600);
            return View();
        }

    }
}
